<?php
/**
 * Created by PhpStorm.
 * User: eugene
 * Date: 2018/3/19
 * Time: 11:59
 */

namespace App\Transformers;


use App\Repos\MemberRepo;
use App\Repos\ParkingRepo;

class MemberTransformer extends Transformer
{
    const STR_LIMIT=15;
    
    public function transform($item)
    {
        return [
            'id'=>$item->id,
            'token'=>$item->token,
            'avatar'=>$item->avatar,
            'nickname'=>str_limit($item->nickname,self::STR_LIMIT,''),
            'golds_format'=>number_format($item->getCredit()),//金币
            'golds'=>$item->getCredit(),//金币
            'levels'=>$item->getUserLevel(),//当前等级
            'car_limit'=>$item->getCarLimit(),//车辆限制
            'global_rank'=>MemberRepo::countGlobalRank($item->getCredit()),
        ];
    }
    
    public function forSimple($item)
    {
        return [
            'id'=>$item->id,
            'avatar'=>$item->avatar,
            'nickname'=>str_limit($item->nickname,self::STR_LIMIT,''),
            'empty_parkings'=>ParkingRepo::getEmptyParks($item->id),
        ];
    }
    
    public function forStranger($item)
    {
        return [
            'id'=>$item->id,
            'avatar'=>$item->avatar,
            'nickname'=>str_limit($item->nickname,self::STR_LIMIT,''),
            'empty_parkings'=>ParkingRepo::getEmptyParks($item->id),
        ];
    }
    
}